package ${cfg.repositoryImplPackage};

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${cfg.repositoryPackage}.${cfg.repositoryName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import java.util.List;

/**
 * ${table.comment!} 仓储实现类
 *
 * @author ${author}
 * @since ${date}
 */
<#assign mapperVarName ="${table.mapperName?uncap_first}">
<#--获取主键字段-->
<#list table.fields as field>
    <#if field.keyFlag>
        <#assign primaryKey = field>
    </#if>
</#list>

@Repository
public class ${cfg.repositoryImplName} implements ${cfg.repositoryName} {

    @Autowired
    private ${table.mapperName} ${mapperVarName};

    @Override
    public PageInfo<${entity}> getPaged${cfg.entityName}List(int pageNum, int pageSize, String ${cfg.searchField}) {
        PageInfo<${entity}> pageInfo = PageHelper.startPage(pageNum, pageSize)
            .doSelectPageInfo(() -> ${mapperVarName}.getPaged${cfg.entityName}List(${cfg.searchField}));

        return pageInfo;
    }

    @Override
    public ${entity} get${cfg.entityName}ById(${primaryKey.propertyType} ${primaryKey.propertyName}) {
        return  ${mapperVarName}.get${cfg.entityName}ById(${primaryKey.propertyName});
    }

    @Override
    public boolean add${cfg.entityName}(${entity} record) {
        return ${mapperVarName}.add${cfg.entityName}(record) > 0;
    }

    @Override
    public boolean edit${cfg.entityName}(${entity} record) {
        return ${mapperVarName}.edit${cfg.entityName}(record) > 0;
    }

    @Override
    public boolean delete${cfg.entityName}ByIds(List<${primaryKey.propertyType}> idList) {
        return ${mapperVarName}.delete${cfg.entityName}ByIds(idList) > 0;
    }
}
